//
//  WQHomeViewController.swift
//  WeiBo
//
//  Created by 张德华 on 7/23/16.
//  Copyright © 2016 ZhangDeHua. All rights reserved.
//

import UIKit
import YYModel
class WQHomeViewController: WQVisitorViewController,UITableViewDelegate,UITableViewDataSource {
    
    let refreshView = UIRefreshControl()
    
    ///------ 全局访问点
    lazy var statusListViewModel: WQStatusListViewModel = WQStatusListViewModel()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupVisitorView()
        
        setupUI()
    }
    
    // MARK: - ************访客视图界面
    func setupVisitorView() {
        
        visitorView?.setupVisitorViewInfo(nil, title: nil)
    }
    
    func setupUI() {
        
        tableView.dataSource = self
        tableView.delegate = self
        
        tableView.tableHeaderView = refreshView
        tableView.estimatedRowHeight = 200
        
        tableView.registerClass(WQStatusCell.self, forCellReuseIdentifier: "statusCell")

    }
    
    override func loadData() {
        
        statusListViewModel.loadHomeData(false) { (isSuc, count) in
            print("======22222222========")
        }
        
        
        WQNetworkTools.sharedManager.loadStatus { (result) in
            
            guard let array = result?["statuses"] as? [[String: AnyObject]] else {
                return
            }
            
            
            var arrayM = [WQStatus]()
            
            for dict in array {
                
                arrayM.append(WQStatus.yy_modelWithJSON(dict)!)
            }
            print(arrayM)
            
        }
        
        
    }
    
    
    
}


// MARK: - ************代理方法
extension WQHomeViewController {
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 10
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCellWithIdentifier("statusCell", forIndexPath: indexPath) as? WQStatusCell
      
        cell?.statusViewModel = statusListViewModel.statusList[indexPath.row]
        
    
        
        
        
        return cell!
    }
    
    
}




